import {
  Column,
  Entity,
  ManyToMany,
  OneToMany,
  PrimaryGeneratedColumn,
  Unique,
  JoinTable,
  OneToOne,
} from 'typeorm';
import { Logs } from '@/modules/logs/logs.entity';
import { Roles } from '@/modules/roles/roles.entity';
import { Profile } from '@/modules/user/profile.entity';

@Entity('admin_user')
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  @Unique(['username'])
  username: string;

  @Column()
  password: string;

  @Column()
  avatar: string;

  @Column({ default: '默认角色' })
  role: string;

  @Column()
  nickname: string;

  @Column()
  active: number;

  @OneToMany('Logs', (logs: object) => logs.user)
  logs: Logs[];

  @ManyToMany('Roles', (roles: object) => roles.users)
  @JoinTable({
    name: 'users_roles',
    joinColumn: { name: 'user_id' },
    inverseJoinColumn: { name: 'role_id' },
  }) // 设置数据库中的中间表名
  roles: Roles[];

  // @OneToOne('Profile')
  // profile: Profile;
}
